using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Medianamik.SubsonicDALProvider.DAL
{
	/// <summary>
	/// Strongly-typed collection for the PropertyX class.
	/// </summary>
	[Serializable]
	public partial class PropertyXCollection : ActiveList<PropertyX,PropertyXCollection> 
	{	   
		public PropertyXCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_Property table.
	/// </summary>
	[Serializable]
	public partial class PropertyX : ActiveRecord<PropertyX>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public PropertyX()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public PropertyX(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public PropertyX(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public PropertyX(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_Property", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarPropertyId = new TableSchema.TableColumn(schema);
				colvarPropertyId.ColumnName = "PropertyId";
				colvarPropertyId.DataType = DbType.Guid;
				colvarPropertyId.MaxLength = 0;
				colvarPropertyId.AutoIncrement = false;
				colvarPropertyId.IsNullable = false;
				colvarPropertyId.IsPrimaryKey = true;
				colvarPropertyId.IsForeignKey = false;
				colvarPropertyId.IsReadOnly = false;
				colvarPropertyId.DefaultSetting = @"";
				colvarPropertyId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPropertyId);
				
				TableSchema.TableColumn colvarTypeId = new TableSchema.TableColumn(schema);
				colvarTypeId.ColumnName = "TypeId";
				colvarTypeId.DataType = DbType.Guid;
				colvarTypeId.MaxLength = 0;
				colvarTypeId.AutoIncrement = false;
				colvarTypeId.IsNullable = false;
				colvarTypeId.IsPrimaryKey = false;
				colvarTypeId.IsForeignKey = true;
				colvarTypeId.IsReadOnly = false;
				colvarTypeId.DefaultSetting = @"";
				
					colvarTypeId.ForeignKeyTableName = "medianamik_Type";
				schema.Columns.Add(colvarTypeId);
				
				TableSchema.TableColumn colvarName = new TableSchema.TableColumn(schema);
				colvarName.ColumnName = "Name";
				colvarName.DataType = DbType.String;
				colvarName.MaxLength = 50;
				colvarName.AutoIncrement = false;
				colvarName.IsNullable = false;
				colvarName.IsPrimaryKey = false;
				colvarName.IsForeignKey = false;
				colvarName.IsReadOnly = false;
				colvarName.DefaultSetting = @"";
				colvarName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarName);
				
				TableSchema.TableColumn colvarIsUnique = new TableSchema.TableColumn(schema);
				colvarIsUnique.ColumnName = "IsUnique";
				colvarIsUnique.DataType = DbType.Boolean;
				colvarIsUnique.MaxLength = 0;
				colvarIsUnique.AutoIncrement = false;
				colvarIsUnique.IsNullable = false;
				colvarIsUnique.IsPrimaryKey = false;
				colvarIsUnique.IsForeignKey = false;
				colvarIsUnique.IsReadOnly = false;
				colvarIsUnique.DefaultSetting = @"";
				colvarIsUnique.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsUnique);
				
				TableSchema.TableColumn colvarGroupName = new TableSchema.TableColumn(schema);
				colvarGroupName.ColumnName = "GroupName";
				colvarGroupName.DataType = DbType.String;
				colvarGroupName.MaxLength = 50;
				colvarGroupName.AutoIncrement = false;
				colvarGroupName.IsNullable = true;
				colvarGroupName.IsPrimaryKey = false;
				colvarGroupName.IsForeignKey = false;
				colvarGroupName.IsReadOnly = false;
				colvarGroupName.DefaultSetting = @"";
				colvarGroupName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarGroupName);
				
				TableSchema.TableColumn colvarDataTypeId = new TableSchema.TableColumn(schema);
				colvarDataTypeId.ColumnName = "DataTypeId";
				colvarDataTypeId.DataType = DbType.Guid;
				colvarDataTypeId.MaxLength = 0;
				colvarDataTypeId.AutoIncrement = false;
				colvarDataTypeId.IsNullable = false;
				colvarDataTypeId.IsPrimaryKey = false;
				colvarDataTypeId.IsForeignKey = true;
				colvarDataTypeId.IsReadOnly = false;
				colvarDataTypeId.DefaultSetting = @"";
				
					colvarDataTypeId.ForeignKeyTableName = "medianamik_DataType";
				schema.Columns.Add(colvarDataTypeId);
				
				TableSchema.TableColumn colvarIsLanguageNeutral = new TableSchema.TableColumn(schema);
				colvarIsLanguageNeutral.ColumnName = "IsLanguageNeutral";
				colvarIsLanguageNeutral.DataType = DbType.Boolean;
				colvarIsLanguageNeutral.MaxLength = 0;
				colvarIsLanguageNeutral.AutoIncrement = false;
				colvarIsLanguageNeutral.IsNullable = false;
				colvarIsLanguageNeutral.IsPrimaryKey = false;
				colvarIsLanguageNeutral.IsForeignKey = false;
				colvarIsLanguageNeutral.IsReadOnly = false;
				colvarIsLanguageNeutral.DefaultSetting = @"";
				colvarIsLanguageNeutral.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsLanguageNeutral);
				
				TableSchema.TableColumn colvarPrecision = new TableSchema.TableColumn(schema);
				colvarPrecision.ColumnName = "Precision";
				colvarPrecision.DataType = DbType.Int32;
				colvarPrecision.MaxLength = 0;
				colvarPrecision.AutoIncrement = false;
				colvarPrecision.IsNullable = true;
				colvarPrecision.IsPrimaryKey = false;
				colvarPrecision.IsForeignKey = false;
				colvarPrecision.IsReadOnly = false;
				colvarPrecision.DefaultSetting = @"";
				colvarPrecision.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPrecision);
				
				TableSchema.TableColumn colvarScale = new TableSchema.TableColumn(schema);
				colvarScale.ColumnName = "Scale";
				colvarScale.DataType = DbType.Int32;
				colvarScale.MaxLength = 0;
				colvarScale.AutoIncrement = false;
				colvarScale.IsNullable = true;
				colvarScale.IsPrimaryKey = false;
				colvarScale.IsForeignKey = false;
				colvarScale.IsReadOnly = false;
				colvarScale.DefaultSetting = @"";
				colvarScale.ForeignKeyTableName = "";
				schema.Columns.Add(colvarScale);
				
				TableSchema.TableColumn colvarLength = new TableSchema.TableColumn(schema);
				colvarLength.ColumnName = "Length";
				colvarLength.DataType = DbType.Int32;
				colvarLength.MaxLength = 0;
				colvarLength.AutoIncrement = false;
				colvarLength.IsNullable = true;
				colvarLength.IsPrimaryKey = false;
				colvarLength.IsForeignKey = false;
				colvarLength.IsReadOnly = false;
				colvarLength.DefaultSetting = @"";
				colvarLength.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLength);
				
				TableSchema.TableColumn colvarAllowNulls = new TableSchema.TableColumn(schema);
				colvarAllowNulls.ColumnName = "AllowNulls";
				colvarAllowNulls.DataType = DbType.Boolean;
				colvarAllowNulls.MaxLength = 0;
				colvarAllowNulls.AutoIncrement = false;
				colvarAllowNulls.IsNullable = false;
				colvarAllowNulls.IsPrimaryKey = false;
				colvarAllowNulls.IsForeignKey = false;
				colvarAllowNulls.IsReadOnly = false;
				colvarAllowNulls.DefaultSetting = @"";
				colvarAllowNulls.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAllowNulls);
				
				TableSchema.TableColumn colvarFlags = new TableSchema.TableColumn(schema);
				colvarFlags.ColumnName = "Flags";
				colvarFlags.DataType = DbType.Int32;
				colvarFlags.MaxLength = 0;
				colvarFlags.AutoIncrement = false;
				colvarFlags.IsNullable = false;
				colvarFlags.IsPrimaryKey = false;
				colvarFlags.IsForeignKey = false;
				colvarFlags.IsReadOnly = false;
				colvarFlags.DefaultSetting = @"";
				colvarFlags.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFlags);
				
				TableSchema.TableColumn colvarWebControlId = new TableSchema.TableColumn(schema);
				colvarWebControlId.ColumnName = "WebControlId";
				colvarWebControlId.DataType = DbType.Guid;
				colvarWebControlId.MaxLength = 0;
				colvarWebControlId.AutoIncrement = false;
				colvarWebControlId.IsNullable = false;
				colvarWebControlId.IsPrimaryKey = false;
				colvarWebControlId.IsForeignKey = true;
				colvarWebControlId.IsReadOnly = false;
				colvarWebControlId.DefaultSetting = @"";
				
					colvarWebControlId.ForeignKeyTableName = "medianamik_WebControl";
				schema.Columns.Add(colvarWebControlId);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_Property",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("PropertyId")]
		public Guid PropertyId 
		{
			get { return GetColumnValue<Guid>(Columns.PropertyId); }

			set { SetColumnValue(Columns.PropertyId, value); }

		}

		  
		[XmlAttribute("TypeId")]
		public Guid TypeId 
		{
			get { return GetColumnValue<Guid>(Columns.TypeId); }

			set { SetColumnValue(Columns.TypeId, value); }

		}

		  
		[XmlAttribute("Name")]
		public string Name 
		{
			get { return GetColumnValue<string>(Columns.Name); }

			set { SetColumnValue(Columns.Name, value); }

		}

		  
		[XmlAttribute("IsUnique")]
		public bool IsUnique 
		{
			get { return GetColumnValue<bool>(Columns.IsUnique); }

			set { SetColumnValue(Columns.IsUnique, value); }

		}

		  
		[XmlAttribute("GroupName")]
		public string GroupName 
		{
			get { return GetColumnValue<string>(Columns.GroupName); }

			set { SetColumnValue(Columns.GroupName, value); }

		}

		  
		[XmlAttribute("DataTypeId")]
		public Guid DataTypeId 
		{
			get { return GetColumnValue<Guid>(Columns.DataTypeId); }

			set { SetColumnValue(Columns.DataTypeId, value); }

		}

		  
		[XmlAttribute("IsLanguageNeutral")]
		public bool IsLanguageNeutral 
		{
			get { return GetColumnValue<bool>(Columns.IsLanguageNeutral); }

			set { SetColumnValue(Columns.IsLanguageNeutral, value); }

		}

		  
		[XmlAttribute("Precision")]
		public int? Precision 
		{
			get { return GetColumnValue<int?>(Columns.Precision); }

			set { SetColumnValue(Columns.Precision, value); }

		}

		  
		[XmlAttribute("Scale")]
		public int? Scale 
		{
			get { return GetColumnValue<int?>(Columns.Scale); }

			set { SetColumnValue(Columns.Scale, value); }

		}

		  
		[XmlAttribute("Length")]
		public int? Length 
		{
			get { return GetColumnValue<int?>(Columns.Length); }

			set { SetColumnValue(Columns.Length, value); }

		}

		  
		[XmlAttribute("AllowNulls")]
		public bool AllowNulls 
		{
			get { return GetColumnValue<bool>(Columns.AllowNulls); }

			set { SetColumnValue(Columns.AllowNulls, value); }

		}

		  
		[XmlAttribute("Flags")]
		public int Flags 
		{
			get { return GetColumnValue<int>(Columns.Flags); }

			set { SetColumnValue(Columns.Flags, value); }

		}

		  
		[XmlAttribute("WebControlId")]
		public Guid WebControlId 
		{
			get { return GetColumnValue<Guid>(Columns.WebControlId); }

			set { SetColumnValue(Columns.WebControlId, value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		private Medianamik.SubsonicDALProvider.DAL.NodePropertyValueCollection colNodePropertyValueRecords;
		public Medianamik.SubsonicDALProvider.DAL.NodePropertyValueCollection NodePropertyValueRecords()
		{
			if(colNodePropertyValueRecords == null)
				colNodePropertyValueRecords = new Medianamik.SubsonicDALProvider.DAL.NodePropertyValueCollection().Where(NodePropertyValue.Columns.PropertyId, PropertyId).Load();
			return colNodePropertyValueRecords;
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a DataType ActiveRecord object related to this PropertyX
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.DataType DataType
		{
			get { return Medianamik.SubsonicDALProvider.DAL.DataType.FetchByID(this.DataTypeId); }

			set { SetColumnValue("DataTypeId", value.DataTypeId); }

		}

		
		
		/// <summary>
		/// Returns a Type ActiveRecord object related to this PropertyX
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.Type Type
		{
			get { return Medianamik.SubsonicDALProvider.DAL.Type.FetchByID(this.TypeId); }

			set { SetColumnValue("TypeId", value.TypeId); }

		}

		
		
		/// <summary>
		/// Returns a WebControl ActiveRecord object related to this PropertyX
		/// 
		/// </summary>
		public Medianamik.SubsonicDALProvider.DAL.WebControl WebControl
		{
			get { return Medianamik.SubsonicDALProvider.DAL.WebControl.FetchByID(this.WebControlId); }

			set { SetColumnValue("WebControlId", value.WebControlID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varPropertyId,Guid varTypeId,string varName,bool varIsUnique,string varGroupName,Guid varDataTypeId,bool varIsLanguageNeutral,int? varPrecision,int? varScale,int? varLength,bool varAllowNulls,int varFlags,Guid varWebControlId)
		{
			PropertyX item = new PropertyX();
			
			item.PropertyId = varPropertyId;
			
			item.TypeId = varTypeId;
			
			item.Name = varName;
			
			item.IsUnique = varIsUnique;
			
			item.GroupName = varGroupName;
			
			item.DataTypeId = varDataTypeId;
			
			item.IsLanguageNeutral = varIsLanguageNeutral;
			
			item.Precision = varPrecision;
			
			item.Scale = varScale;
			
			item.Length = varLength;
			
			item.AllowNulls = varAllowNulls;
			
			item.Flags = varFlags;
			
			item.WebControlId = varWebControlId;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(Guid varPropertyId,Guid varTypeId,string varName,bool varIsUnique,string varGroupName,Guid varDataTypeId,bool varIsLanguageNeutral,int? varPrecision,int? varScale,int? varLength,bool varAllowNulls,int varFlags,Guid varWebControlId)
		{
			PropertyX item = new PropertyX();
			
				item.PropertyId = varPropertyId;
			
				item.TypeId = varTypeId;
			
				item.Name = varName;
			
				item.IsUnique = varIsUnique;
			
				item.GroupName = varGroupName;
			
				item.DataTypeId = varDataTypeId;
			
				item.IsLanguageNeutral = varIsLanguageNeutral;
			
				item.Precision = varPrecision;
			
				item.Scale = varScale;
			
				item.Length = varLength;
			
				item.AllowNulls = varAllowNulls;
			
				item.Flags = varFlags;
			
				item.WebControlId = varWebControlId;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn PropertyIdColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn TypeIdColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn NameColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn IsUniqueColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        public static TableSchema.TableColumn GroupNameColumn
        {
            get { return Schema.Columns[4]; }

        }

        
        
        
        public static TableSchema.TableColumn DataTypeIdColumn
        {
            get { return Schema.Columns[5]; }

        }

        
        
        
        public static TableSchema.TableColumn IsLanguageNeutralColumn
        {
            get { return Schema.Columns[6]; }

        }

        
        
        
        public static TableSchema.TableColumn PrecisionColumn
        {
            get { return Schema.Columns[7]; }

        }

        
        
        
        public static TableSchema.TableColumn ScaleColumn
        {
            get { return Schema.Columns[8]; }

        }

        
        
        
        public static TableSchema.TableColumn LengthColumn
        {
            get { return Schema.Columns[9]; }

        }

        
        
        
        public static TableSchema.TableColumn AllowNullsColumn
        {
            get { return Schema.Columns[10]; }

        }

        
        
        
        public static TableSchema.TableColumn FlagsColumn
        {
            get { return Schema.Columns[11]; }

        }

        
        
        
        public static TableSchema.TableColumn WebControlIdColumn
        {
            get { return Schema.Columns[12]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string PropertyId = @"PropertyId";
			 public static string TypeId = @"TypeId";
			 public static string Name = @"Name";
			 public static string IsUnique = @"IsUnique";
			 public static string GroupName = @"GroupName";
			 public static string DataTypeId = @"DataTypeId";
			 public static string IsLanguageNeutral = @"IsLanguageNeutral";
			 public static string Precision = @"Precision";
			 public static string Scale = @"Scale";
			 public static string Length = @"Length";
			 public static string AllowNulls = @"AllowNulls";
			 public static string Flags = @"Flags";
			 public static string WebControlId = @"WebControlId";
						
		}

		#endregion
		
		
		
	}

}

